<!DOCTYPE html>
<html lang="en">
    <!-- title -->


    

<!-- keywords -->



<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="author" content="Coder XiaoLiu">
    <meta name="renderer" content="webkit">
    <meta name="copyright" content="Coder XiaoLiu">
    
        <meta name="keywords" content="hexo,spring,java">
    
    <meta name="description" content="">
    <meta name="description" content="What is AES algorithm?  密码学中的高级加密标准（Advanced Encryption Standard，AES），又称Rijndael加密法，是美国联邦政府采用的一种区块加密标准。  如上所述，AES是一个对称分组密码算法，旨在取代DES成为广泛使用的标准。">
<meta property="og:type" content="article">
<meta property="og:title" content="初识AES算法">
<meta property="og:url" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="What is AES algorithm?  密码学中的高级加密标准（Advanced Encryption Standard，AES），又称Rijndael加密法，是美国联邦政府采用的一种区块加密标准。  如上所述，AES是一个对称分组密码算法，旨在取代DES成为广泛使用的标准。">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/aes_algorithm_type.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/AES_%E5%8A%A0%E5%AF%86%E8%BF%87%E7%A8%8B.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/AES_in_state_out.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/AES_key_extended_key.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/AES_encrypt_decrypt.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/sbox_encrypt.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/example_of_subsititue_bytes.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/example_of_shift_row.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/example_of_mix_columns.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/add_round_key.png">
<meta property="og:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/example_of_add_round_key.png">
<meta property="article:published_time" content="2021-11-06T12:26:10.000Z">
<meta property="article:modified_time" content="2022-05-05T09:08:37.531Z">
<meta property="article:author" content="Coder XiaoLiu">
<meta property="article:tag" content="AES算法">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/aes_algorithm_type.png">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="icon" href="/assets/favicon.ico">
    
    <title>初识AES算法 · XiaoLiu&#39;s Studio</title>
    <!-- /*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
/* This file is meant as a standalone workflow for
- testing support for link[rel=preload]
- enabling async CSS loading in browsers that do not support rel=preload
- applying rel preload css once loaded, whether supported or not.
*/ -->
<script>
    (function (w) {
        'use strict'
        // rel=preload support test
        if (!w.loadCSS) {
            w.loadCSS = function () {}
        }
        // define on the loadCSS obj
        var rp = (loadCSS.relpreload = {})
        // rel=preload feature support test
        // runs once and returns a function for compat purposes
        rp.support = (function () {
            var ret
            try {
                ret = w.document.createElement('link').relList.supports('preload')
            } catch (e) {
                ret = false
            }
            return function () {
                return ret
            }
        })()

        // if preload isn't supported, get an asynchronous load by using a non-matching media attribute
        // then change that media back to its intended value on load
        rp.bindMediaToggle = function (link) {
            // remember existing media attr for ultimate state, or default to 'all'
            var finalMedia = link.media || 'all'

            function enableStylesheet() {
                link.media = finalMedia
            }

            // bind load handlers to enable media
            if (link.addEventListener) {
                link.addEventListener('load', enableStylesheet)
            } else if (link.attachEvent) {
                link.attachEvent('onload', enableStylesheet)
            }

            // Set rel and non-applicable media type to start an async request
            // note: timeout allows this to happen async to let rendering continue in IE
            setTimeout(function () {
                link.rel = 'stylesheet'
                link.media = 'only x'
            })
            // also enable media after 3 seconds,
            // which will catch very old browsers (android 2.x, old firefox) that don't support onload on link
            setTimeout(enableStylesheet, 3000)
        }

        // loop through link elements in DOM
        rp.poly = function () {
            // double check this to prevent external calls from running
            if (rp.support()) {
                return
            }
            var links = w.document.getElementsByTagName('link')
            for (var i = 0; i < links.length; i++) {
                var link = links[i]
                // qualify links to those with rel=preload and as=style attrs
                if (
                    link.rel === 'preload' &&
                    link.getAttribute('as') === 'style' &&
                    !link.getAttribute('data-loadcss')
                ) {
                    // prevent rerunning on link
                    link.setAttribute('data-loadcss', true)
                    // bind listeners to toggle media back
                    rp.bindMediaToggle(link)
                }
            }
        }

        // if unsupported, run the polyfill
        if (!rp.support()) {
            // run once at least
            rp.poly()

            // rerun poly on an interval until onload
            var run = w.setInterval(rp.poly, 500)
            if (w.addEventListener) {
                w.addEventListener('load', function () {
                    rp.poly()
                    w.clearInterval(run)
                })
            } else if (w.attachEvent) {
                w.attachEvent('onload', function () {
                    rp.poly()
                    w.clearInterval(run)
                })
            }
        }

        // commonjs
        if (typeof exports !== 'undefined') {
            exports.loadCSS = loadCSS
        } else {
            w.loadCSS = loadCSS
        }
    })(typeof global !== 'undefined' ? global : this)
</script>

    <style type="text/css">
    @font-face {
        font-family: 'Oswald-Regular';
        src: url("/font/Oswald-Regular.ttf");
    }

    body {
        margin: 0;
    }

    header,
    footer,
    .back-top,
    .sidebar,
    .container,
    .site-intro-meta,
    .toc-wrapper {
        display: none;
    }

    .site-intro {
        position: relative;
        z-index: 3;
        width: 100%;
        /* height: 50vh; */
        overflow: hidden;
    }

    .site-intro-placeholder {
        position: absolute;
        z-index: -2;
        top: 0;
        left: 0;
        width: calc(100% + 300px);
        height: 100%;
        background: repeating-linear-gradient(-45deg, #444 0, #444 80px, #333 80px, #333 160px);
        background-position: center center;
        transform: translate3d(-226px, 0, 0);
        animation: gradient-move 2.5s ease-out 0s infinite;
    }

    @keyframes gradient-move {
        0% {
            transform: translate3d(-226px, 0, 0);
        }
        100% {
            transform: translate3d(0, 0, 0);
        }
    }
</style>

    <link rel="preload" href="/css/style.css?v=20211217" as="style" onload="this.onload=null;this.rel='stylesheet'">
    <link rel="preload" href="/css/dark.css?v=20211217" as="style">
    <link rel="stylesheet" href="/css/dark.css">
    <link rel="stylesheet" href="/css/mobile.css?v=20211217" media="(max-width: 960px)">
    <link rel="preload" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
    <link rel="preload" href="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" as="script">
    <link rel="preload" href="/scripts/main.js?v=20211217" as="script">
    <link rel="preload" href="/scripts/dark.js?v=20211217" as="script">
    <link rel="preload" href="/font/Oswald-Regular.ttf" as="font" crossorigin>
    <link rel="preload" href="https://at.alicdn.com/t/font_327081_1dta1rlogw17zaor.woff" as="font" crossorigin>
    <!-- algolia -->
    
    <!-- 百度统计  -->
    
    <!-- 谷歌统计  -->
    
<meta name="generator" content="Hexo 5.4.0"></head>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <script type="text/javascript">
        if (typeof window.$ == undefined) {
            console.warn('jquery load from jsdelivr failed, will load local script')
            document.write('<script src="/lib/jquery.min.js" />')
        }
    </script>
    
        <body class="post-body">
    
        <!-- header -->
        <header class="header header-mobile">
    <!-- top read progress line -->
    <div class="header-element">
        <div class="read-progress"></div>
    </div>
    <!-- sidebar menu button -->
    <div class="header-element">
        
            <div class="header-sidebar-menu">
        
            
                <div style="padding-left: 1px;">&#xe775;</div>
            
        </div>
    </div>
    <!-- header actions -->
    <div class="header-actions">
        <!-- theme mode switch button -->
        <span class="header-theme-btn header-element">
            <i class="fas fa-adjust"></i>
        </span>
        <!-- back to home page text -->
        <span class="home-link header-element">
            <a href=/>XiaoLiu's Studio</a>
        </span>
    </div>
    <!-- toggle banner for post layout -->
    
        
            <div class="banner">
        
            <div class="blog-title header-element">
                <a href="/">XiaoLiu&#39;s Studio</a>
            </div>
            <div class="post-title header-element">
                <a href="#" class="post-name">初识AES算法</a>
            </div>
        </div>
    
</header>

        <!-- fixed footer -->
        <footer class="footer-fixed">
    <!-- back to top button -->
    <div class="footer-fixed-element">
        
            <div class="back-top back-top-hidden">
        
        
            <div>&#xe639;</div>
        
        </div>
    </div>
</footer>

        <!-- wrapper -->
        <div class="wrapper">
            <div class="site-intro" style="







    height:50vh;

">
    
    <!-- 主页  -->
    
        
    <!-- 404页  -->
            
    <div class="site-intro-placeholder"></div>
    <div class="site-intro-img" style="background-image: url(/intro/post-bg.jpg)"></div>
    <div class="site-intro-meta">
        <!-- 标题  -->
        <h1 class="intro-title">
            <!-- 主页  -->
            
                初识AES算法
            <!-- 404 -->
            
        </h1>
        <!-- 副标题 -->
        <p class="intro-subtitle">
            <!-- 主页副标题  -->
            
                
            <!-- 404 -->
            
        </p>
        <!-- 文章页 meta -->
        
            <div class="post-intros">
                <!-- 文章页标签  -->
                
                    <div class= post-intro-tags >
    
    
        <a class="post-tag" href="javascript:void(0);" data-tags="AES算法">AES算法</a>
    
</div>

                
                
                    <div class="post-intro-read">
                        <span>Word count: <span class="post-count word-count">2.1k</span>Reading time: <span class="post-count reading-time">7 min</span></span>
                    </div>
                
                <div class="post-intro-meta">
                    <!-- 撰写日期 -->
                    <span class="iconfont-archer post-intro-calander">&#xe676;</span>
                    <span class="post-intro-time">2021/11/06</span>
                    <!-- busuanzi -->
                    
                        <span id="busuanzi_container_page_pv" class="busuanzi-pv">
                            <span class="iconfont-archer post-intro-busuanzi">&#xe602;</span>
                            <span id="busuanzi_value_page_pv"></span>
                        </span>
                    
                    <!-- 文章分享 -->
                    <span class="share-wrapper">
                        <span class="iconfont-archer share-icon">&#xe71d;</span>
                        <span class="share-text">Share</span>
                        <ul class="share-list">
                            <li class="iconfont-archer share-qr" data-type="qr">&#xe75b;
                                <div class="share-qrcode"></div>
                            </li>
                            <li class="iconfont-archer" data-type="weibo">&#xe619;</li>
                            <li class="iconfont-archer" data-type="qzone">&#xe62e;</li>
                            <li class="iconfont-archer" data-type="twitter">&#xe634;</li>
                            <li class="iconfont-archer" data-type="facebook">&#xe67a;</li>
                        </ul>
                    </span>
                </div>
            </div>
        
    </div>
</div>

            <script>
  // get user agent
  function getBrowserVersions() {
    var u = window.navigator.userAgent
    return {
      userAgent: u,
      trident: u.indexOf('Trident') > -1, //IE内核
      presto: u.indexOf('Presto') > -1, //opera内核
      webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
      gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
      mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
      ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
      android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
      iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者安卓QQ浏览器
      iPad: u.indexOf('iPad') > -1, //是否为iPad
      webApp: u.indexOf('Safari') == -1, //是否为web应用程序，没有头部与底部
      weixin: u.indexOf('MicroMessenger') == -1, //是否为微信浏览器
      uc: u.indexOf('UCBrowser') > -1, //是否为android下的UC浏览器
    }
  }
  var browser = {
    versions: getBrowserVersions(),
  }
  console.log('userAgent: ' + browser.versions.userAgent)

  // callback
  function fontLoaded() {
    console.log('font loaded')
    if (document.getElementsByClassName('site-intro-meta')) {
      document
        .getElementsByClassName('intro-title')[0]
        .classList.add('intro-fade-in')
      document
        .getElementsByClassName('intro-subtitle')[0]
        .classList.add('intro-fade-in')
      var postIntros = document.getElementsByClassName('post-intros')[0]
      if (postIntros) {
        postIntros.classList.add('post-fade-in')
      }
    }
  }

  // UC不支持跨域，所以直接显示
  function asyncCb() {
    if (browser.versions.uc) {
      console.log('UCBrowser')
      fontLoaded()
    } else {
      WebFont.load({
        custom: {
          families: ['Oswald-Regular'],
        },
        loading: function () {
          // 所有字体开始加载
          // console.log('font loading');
        },
        active: function () {
          // 所有字体已渲染
          fontLoaded()
        },
        inactive: function () {
          // 字体预加载失败，无效字体或浏览器不支持加载
          console.log('inactive: timeout')
          fontLoaded()
        },
        timeout: 5000, // Set the timeout to two seconds
      })
    }
  }

  function asyncErr() {
    console.warn('script load from CDN failed, will load local script')
  }

  // load webfont-loader async, and add callback function
  function async(u, cb, err) {
    var d = document,
      t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0]
    o.src = u
    if (cb) {
      o.addEventListener(
        'load',
        function (e) {
          cb(null, e)
        },
        false
      )
    }
    if (err) {
      o.addEventListener(
        'error',
        function (e) {
          err(null, e)
        },
        false
      )
    }
    s.parentNode.insertBefore(o, s)
  }

  var asyncLoadWithFallBack = function (arr, success, reject) {
    var currReject = function () {
      reject()
      arr.shift()
      if (arr.length) async(arr[0], success, currReject)
    }

    async(arr[0], success, currReject)
  }

  asyncLoadWithFallBack(
    [
      'https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.min.js',
      'https://cdn.bootcss.com/webfont/1.6.28/webfontloader.js',
      "/lib/webfontloader.min.js",
    ],
    asyncCb,
    asyncErr
  )
</script>

            <img class="loading" src="/assets/loading.svg" style="display: block; margin: 6rem auto 0 auto; width: 6rem; height: 6rem;" />
            <div class="container container-unloaded">
                <main class="main post-page">
    <article class="article-entry">
        <h2 id="what-is-aes-algorithm">What is AES algorithm?</h2>
<blockquote>
<p>密码学中的高级加密标准（Advanced Encryption
Standard，AES），又称Rijndael<a
target="_blank" rel="noopener" href="https://baike.baidu.com/item/加密法/9684302">加密法</a>，是<a
target="_blank" rel="noopener" href="https://baike.baidu.com/item/美国联邦政府/8370227">美国联邦政府</a>采用的一种区块加密标准。</p>
</blockquote>
<p>如上所述，AES是一个对称分组密码算法，旨在取代DES成为广泛使用的标准。</p>
<span id="more"></span>
<p>本文参考：<a
target="_blank" rel="noopener" href="https://blog.csdn.net/qq_28205153/article/details/55798628">AES加密算法的详细介绍与实现</a></p>
<h2 id="aes总体结构">AES总体结构</h2>
<p>下图展示了AES加密过程的总体结构，明文分组的长度统一为128位，即16个字节。我们根据<strong>密钥长度</strong>可以将算法称为AES-128、AES-192和AES-256。</p>
<img src="/2021/11/06/first_sense_of_AES_algorithm/aes_algorithm_type.png" class="" title="AES算法分类">
<p>通过分析AES加密算法的过程图我们可以将该过程描述为：</p>
<p>128位的明文输入，在经过一系列的处理后，输出128位的密文。同时，解密算法也是同理，通过相同的过程，将密文解密成明文。</p>
<img src="/2021/11/06/first_sense_of_AES_algorithm/AES_%E5%8A%A0%E5%AF%86%E8%BF%87%E7%A8%8B.png" class="" title="AES的加密过程">
<center>
AES的加密过程
</center>
<p>密码由N轮组成，其中加密的轮数依赖于密码的长度，如图中表格所示。<strong>前N-1轮</strong>由4个不同的变换组成：字节代替、行位移、列混淆和轮密钥加。<strong>最后一轮</strong>仅包含3个变换。而在<strong>第一轮前面</strong>有一个起始的单变换（轮密钥加）可以看成是第0轮。每一轮的每个变换输入一个或多个4*4的矩阵，输出一个4*4的矩阵，最后一轮的输出为密文。同样，密钥扩展函数产生N+1轮密钥，他们是互不相同的4*4的矩阵，每一个轮密钥作为每轮的轮密钥加变换的一个输入。</p>
<img src="/2021/11/06/first_sense_of_AES_algorithm/AES_in_state_out.png" class="" title="AES的输入、状态和输出">
<center>
AES的输入、状态和输出矩阵
</center>
<img src="/2021/11/06/first_sense_of_AES_algorithm/AES_key_extended_key.png" class="" title="AES的密钥与密钥扩展">
<center>
AES的密钥与密钥扩展
</center>
<p><strong>注：</strong></p>
<ul>
<li>明文的输入为128的分组，这个分组被描述为4*4的字节方阵，这个分组被复制到state分组，在加密或解密的各个过程被修改。</li>
<li>密钥也被描述为字节方阵，紧接着，这个密钥方阵被扩展为密钥字阵列，128位（16字）的密钥被扩展为44字的序列。</li>
<li>矩阵中的字节都是按照列进行排序的，即128位的明文分组的前四个字节按顺序被放在in矩阵的第一列，紧接着后四个字被放在了第二列，等等。扩展密钥的前四个字（形成一个字）被放在了w矩阵的第一列。</li>
</ul>
<h2 id="aes详细结构">AES详细结构</h2>
<p>下图更加详细的解释了AES算法的过程，指明了每轮的变化顺序，并展示了相应的解密函数，图中<strong>加密过程</strong>是沿着页面向下，<strong>解密过程</strong>是沿着页面向上。</p>
<img src="/2021/11/06/first_sense_of_AES_algorithm/AES_encrypt_decrypt.png" class="" title="AES的加密和解密过程">
<center>
AES的加密和解密过程
</center>
<p><strong>关于AES的结构：</strong></p>
<ul>
<li><p>AES结构的一个显著特征是他不是Feistel结构。</p>
<blockquote>
<p>Feistel（法伊斯特尔）密码结构，在密码学研究中，Feistel
密码结构是用于分组密码中的一种对称结构。以它的发明者 Horst Feistel
为名，而Horst Feistel 本人是一位物理学家兼密码学家，在他为 IBM
工作的时候，为Feistel
密码结构的研究奠定了基础。很多密码标准都采用了Feistel
结构，其中包括DES。Feistel
的优点在于：由于它是对称的密码结构，所以对信息的加密和解密的过程就极为相似，甚至完全一样。这就使得在实施的过程中，对编码量和线路传输的要求就减少了几乎一半。</p>
</blockquote>
<p>AES算法没有使用Feistel结构，而是在每一轮都是用代替和混淆将整个数据分组作为一个单一的矩阵进行处理。</p></li>
<li><p>输入的密钥被扩展成由44个32位字所组成的数组w[i]，从图中可以看出，每轮有4个不同的字节(128位)作为该轮的轮密钥输入。</p></li>
<li><p>由四个不同的阶段组成，包括一个置换和三个代替</p>
<ul>
<li>字节代替（Subsititue
Bytes）：用一个S盒完成分组的字节到字节的代替。</li>
<li>行位移（Shift Row）：一个简单的置换。</li>
<li>列混淆（Mix
Columns）：利用域GF(2<sup>8</sup>)上的算数特性的一个代替。</li>
<li>轮密钥加（Add Round
Key）：当前分组可扩展密钥的一部分进行按位XOR。</li>
</ul></li>
<li><p>算法的结构非常简单，在解密和加密过程中，首先进行<strong>轮密钥加</strong>操作，紧接着进行1-9轮的<strong>字节代替</strong>、<strong>行位移</strong>、<strong>列混淆</strong>和<strong>轮密钥加操作</strong>，第10轮进行除去<strong>列混淆</strong>之外的三个操作。</p></li>
<li><p>该算法以<strong>轮密钥加</strong>开始，以<strong>轮密钥加</strong>结束，仅在<strong>轮密钥加</strong>阶段使用密钥。</p>
<ul>
<li>如果在算法的开始或结束阶段使用不需要密钥的运算，在不知道密钥的情况下就能对其取逆，降低了算法的安全性。</li>
</ul></li>
<li><p>轮密钥加实质上是一种Vernam密码形式。</p>
<blockquote>
<p>Vernam加密法也称一次一密(One-Time-Pad)，用随机的非重复的字符集合作为输出密文。这里最重要的是，一旦使用了变换的输入密文，就不再在任何其他消息中使用这个输入密文(因此是一次性的)。输入密文的长度等于原消息明文的长度。</p>
</blockquote>
<p>对于AES算法，我们可以将其看作对一个分组的XOR加密（轮密钥加），紧接着对这个分组进行混淆（字节代替、行位移和列混淆三个操作），再对这个分组进行XOR加密，如此交替进行。</p></li>
<li><p>每个阶段均可逆。对于字节代替、行位移和列混淆都可以找到其对应的逆函数。对于轮密钥加，只需要在每一轮使用相同的轮密钥和分组异或。</p></li>
</ul>
<h2 id="aes的变换函数">AES的变换函数</h2>
<p>本章节仅简单介绍AES各个变换函数的基本内容，具体深入了解其运算机制，请参见：</p>
<h3 id="字节代替变换subsititue-bytes">字节代替变换（Subsititue
Bytes）</h3>
<img src="/2021/11/06/first_sense_of_AES_algorithm/sbox_encrypt.png" class="" title="S盒置换表格">
<p>将矩阵中的每个元素的<strong>高四位</strong>映射为行号，<strong>低四位</strong>映射为列号，在S盒的置换表中找到对应的元素，将现有元素代替。</p>
<p>下面是一个字节代替变换的例子：</p>
<img src="/2021/11/06/first_sense_of_AES_algorithm/example_of_subsititue_bytes.png" class="" title="字节代换例子">
<h3 id="行移位变换shift-row">行移位变换（Shift Row）</h3>
<p>行以为可以理解为state矩阵的每一行左移的操作。</p>
<p>state矩阵的第一行保持不变，第二行左移一位，第三行左移两位，第四行左移三位。</p>
<p>下面是一个行移位变换的例子：</p>
<img src="/2021/11/06/first_sense_of_AES_algorithm/example_of_shift_row.png" class="" title="行移位变换例子">
<p><strong>逆向行移位变换将状态中的后三行执行相反方向的移位操作，如第二行循环右移一个字节，三四行同理。</strong></p>
<h3 id="列混淆变换mix-columns">列混淆变换（Mix Columns）</h3>
<p>列混淆变换的正向变换是对每一列进行独立的进行操作。混淆后的矩阵的元素<span
class="math inline">\(s_{i,j}&#39;\)</span>是通过如下的矩阵乘法得到的。
<span class="math display">\[
\begin{bmatrix}
    02 &amp; 03 &amp; 01 &amp; 01\\
    01 &amp; 02 &amp; 03 &amp; 01\\
    01 &amp; 01 &amp; 02 &amp; 03\\
    03 &amp; 01 &amp; 01 &amp; 02\\
\end{bmatrix}
\begin{bmatrix}
    s_{0,0} &amp; s_{0,1} &amp; s_{0,2} &amp; s_{0,3}\\
    s_{1,0} &amp; s_{1,1} &amp; s_{1,2} &amp; s_{1,3}\\
    s_{2,0} &amp; s_{2,1} &amp; s_{2,2} &amp; s_{2,3}\\
    s_{3,0} &amp; s_{3,1} &amp; s_{3,2} &amp; s_{3,3}\\
\end{bmatrix}
=
\begin{bmatrix}
    s_{0,0}&#39; &amp; s_{0,1}&#39; &amp; s_{0,2}&#39; &amp;
s_{0,3}&#39;\\
    s_{1,0}&#39; &amp; s_{1,1}&#39; &amp; s_{1,2}&#39; &amp;
s_{1,3}&#39;\\
    s_{2,0}&#39; &amp; s_{2,1}&#39; &amp; s_{2,2}&#39; &amp;
s_{2,3}&#39;\\
    s_{3,0}&#39; &amp; s_{3,1}&#39; &amp; s_{3,2}&#39; &amp;
s_{3,3}&#39;\\
\end{bmatrix}
\]</span></p>
<p>混淆后的矩阵的每个元素<span
class="math inline">\(s_{i,j}&#39;\)</span>都是一行和一列中的对应元素的乘积之和。这里的乘法和加法都是定义在<span
class="math inline">\(GF(2^8)\)</span>上的。</p>
<p>下面是一个列混淆变换的例子：</p>
<img src="/2021/11/06/first_sense_of_AES_algorithm/example_of_mix_columns.png" class="" title="列混淆变换例子">
<h3 id="轮密钥加变换add-round-key">轮密钥加变换（Add Round Key）</h3>
<p>轮密钥加变换可以看作128位的state矩阵与128位的轮密钥进行XOR，如下图所示。该操作是state矩阵的一列中的四个字与轮密钥的一个字进行列间的操作。</p>
<img src="/2021/11/06/first_sense_of_AES_algorithm/add_round_key.png" class="" title="轮密钥加变换示意图">
<p>下面是一个轮密钥加变换的例子：</p>
<img src="/2021/11/06/first_sense_of_AES_algorithm/example_of_add_round_key.png" class="" title="轮密钥加变换例子">
<p><strong>注：</strong></p>
<p><strong>本文对AES加密过程的各个环节进行了简单的说明，对每个环节的具体描述将在后续继续展开。</strong></p>

    </article>
    <!-- license -->
    
        <div class="license-wrapper">
            <p>Author：<a href="https://mnjic.gitee.io">Coder XiaoLiu</a>
            <p>Link：<a href="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/">https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/</a>
            <p>Publish date：<a href="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/">November 6th 2021, 8:26:10 pm</a>
            <p>Update date：<a href="https://mnjic.gitee.io/2021/11/06/first_sense_of_AES_algorithm/">May 5th 2022, 5:08:37 pm</a>
            <p>License：本文采用<a rel="license noopener" target="_blank" href="http://creativecommons.org/licenses/by-nc/4.0/">知识共享署名-非商业性使用 4.0 国际许可协议</a>进行许可</p>
        </div>
    
    <!-- paginator -->
    <ul class="post-paginator">
        <li class="next">
            
                <div class="nextSlogan">Next Post</div>
                <a href="/2022/05/05/23.Merge%20k%20Sorted%20Lists/" title="LeetCode.23.合并K个链表">
                    <div class="nextTitle">LeetCode.23.合并K个链表</div>
                </a>
            
        </li>
        <li class="previous">
            
                <div class="prevSlogan">Previous Post</div>
                <a href="/2021/11/06/Create_C_Project_with_VS2019/" title="使用VS 2019创建一个C语言项目">
                    <div class="prevTitle">使用VS 2019创建一个C语言项目</div>
                </a>
            
        </li>
    </ul>
    <!-- comment -->
    
        <div class="post-comment">
            <!-- 来必力 City 版安装代码 -->


            

            

            

            <!-- utteranc评论 -->


            <!-- partial('_partial/comment/changyan') -->
            <!--PC版-->


            
            

            

        </div>
    
    <!-- timeliness note -->
    <!-- idea from: https://hexo.fluid-dev.com/posts/hexo-injector/#%E6%96%87%E7%AB%A0%E6%97%B6%E6%95%88%E6%80%A7%E6%8F%90%E7%A4%BA -->
    
    <!-- Mathjax -->
    
        
    <script>
        MathJax = {
            tex: {
                inlineMath: [['$', '$'], ['\\(', '\\)']],
                skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
            }
        };
    </script>

    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3.2.0/es5/tex-mml-chtml.js"></script>


    
</main>

                <!-- profile -->
                
            </div>
            <footer class="footer footer-unloaded">
    <!-- social  -->
    
        <div class="social">
            
    
        
            
                <a href="mailto:269810721@qq.com" class="iconfont-archer email" title=email ></a>
            
        
    
        
            
                <a href="//github.com/mnjic-503" class="iconfont-archer github" target="_blank" title=github></a>
            
        
    
        
            
                <span class="iconfont-archer wechat" title=wechat>
                    
                    <img class="profile-qr" src="/assets/weichat_qrcode.jpg" />
                </span>
            
        
    
        
            
                <span class="iconfont-archer qq" title=qq>
                    
                    <img class="profile-qr" src="/assets/QQ_qrcode.jpg" />
                </span>
            
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    


        </div>
    
    <!-- powered by Hexo  -->
    <div class="copyright">
        <span id="hexo-power">Powered by <a href="https://hexo.io/" target="_blank">Hexo</a></span><span class="iconfont-archer power">&#xe635;</span><span id="theme-info">theme <a href="https://github.com/fi3ework/hexo-theme-archer" target="_blank">Archer</a></span>
    </div>
    <!-- website approve for Chinese user -->
    
    <!-- 不蒜子  -->
    
        <div class="busuanzi-container">
            
             
                <span id="busuanzi_container_site_pv">PV: <span id="busuanzi_value_site_pv"></span> :)</span>
            
        </div>
    	
</footer>

        </div>
        <!-- toc -->
        
            <div class="toc-wrapper toc-wrapper-loding" style=







    top:50vh;

>
                <div class="toc-catalog">
                    <span class="iconfont-archer catalog-icon">&#xe613;</span><span>CATALOG</span>
                </div>
                <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#what-is-aes-algorithm"><span class="toc-number">1.</span> <span class="toc-text">What is AES algorithm?</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#aes%E6%80%BB%E4%BD%93%E7%BB%93%E6%9E%84"><span class="toc-number">2.</span> <span class="toc-text">AES总体结构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#aes%E8%AF%A6%E7%BB%86%E7%BB%93%E6%9E%84"><span class="toc-number">3.</span> <span class="toc-text">AES详细结构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#aes%E7%9A%84%E5%8F%98%E6%8D%A2%E5%87%BD%E6%95%B0"><span class="toc-number">4.</span> <span class="toc-text">AES的变换函数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E8%8A%82%E4%BB%A3%E6%9B%BF%E5%8F%98%E6%8D%A2subsititue-bytes"><span class="toc-number">4.1.</span> <span class="toc-text">字节代替变换（Subsititue
Bytes）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A1%8C%E7%A7%BB%E4%BD%8D%E5%8F%98%E6%8D%A2shift-row"><span class="toc-number">4.2.</span> <span class="toc-text">行移位变换（Shift Row）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%97%E6%B7%B7%E6%B7%86%E5%8F%98%E6%8D%A2mix-columns"><span class="toc-number">4.3.</span> <span class="toc-text">列混淆变换（Mix Columns）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BD%AE%E5%AF%86%E9%92%A5%E5%8A%A0%E5%8F%98%E6%8D%A2add-round-key"><span class="toc-number">4.4.</span> <span class="toc-text">轮密钥加变换（Add Round Key）</span></a></li></ol></li></ol>
            </div>
        
        <!-- sidebar -->
        <div class="sidebar sidebar-hide">
    <ul class="sidebar-tabs sidebar-tabs-active-0">
        <li class="sidebar-tab-archives"><span class="iconfont-archer">&#xe67d;</span><span class="tab-name">Archive</span></li>
        <li class="sidebar-tab-tags"><span class="iconfont-archer">&#xe61b;</span><span class="tab-name">Tag</span></li>
        <li class="sidebar-tab-categories"><span class="iconfont-archer">&#xe666;</span><span class="tab-name">Cate</span></li>
    </ul>
    <div class="sidebar-content sidebar-content-show-archive">
        <div class="sidebar-panel-archives">
    <!-- 在 ejs 中将 archive 按照时间排序 -->
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    
    
    
    <div class="total-and-search">
        <div class="total-archive">
        Total : 11
        </div>
        <!-- search  -->
        
    </div>
    
    <div class="post-archive">
    
        
            
            
            <div class="archive-year"> 2022 </div>
            <ul class="year-list">
            
        
        <li class="archive-post-item">
            <span class="archive-post-date">05/06</span>
            <a class="archive-post-title" href="/2022/05/06/11.ContainerWithMostWater/">LeetCode.11.盛水最多的容器</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">05/05</span>
            <a class="archive-post-title" href="/2022/05/05/1024.VideoStitching/">LeetCode.1024.视频拼接</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">05/05</span>
            <a class="archive-post-title" href="/2022/05/05/23.Merge%20k%20Sorted%20Lists/">LeetCode.23.合并K个链表</a>
        </li>
    
        
            
            
                
                </ul>
            
            <div class="archive-year"> 2021 </div>
            <ul class="year-list">
            
        
        <li class="archive-post-item">
            <span class="archive-post-date">11/06</span>
            <a class="archive-post-title" href="/2021/11/06/first_sense_of_AES_algorithm/">初识AES算法</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">11/06</span>
            <a class="archive-post-title" href="/2021/11/06/Create_C_Project_with_VS2019/">使用VS 2019创建一个C语言项目</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">11/03</span>
            <a class="archive-post-title" href="/2021/11/03/SpringBoot_underlying_annotation/">SpringBoot底层注解</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">11/02</span>
            <a class="archive-post-title" href="/2021/11/02/SpringBoot_auto_configuration/">SpringBoot依赖管理特性</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">11/01</span>
            <a class="archive-post-title" href="/2021/11/01/SpringBoot2_introduction/">SpringBoot2入门</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">11/01</span>
            <a class="archive-post-title" href="/2021/11/01/SpringBoot2_data/">SpringBoot2学习资料</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">11/01</span>
            <a class="archive-post-title" href="/2021/11/01/Spring_or_SpringBoot/">Spring与SpringBoot</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">10/26</span>
            <a class="archive-post-title" href="/2021/10/26/hello-world/">Hello World</a>
        </li>
    
    </div>
</div>

        <div class="sidebar-panel-tags">
    <div class="sidebar-tags-name">
        
            <span class="sidebar-tag-name" data-tags="LeetCode">
                <span class="iconfont-archer">&#xe606;</span>
                LeetCode
            </span>
        
            <span class="sidebar-tag-name" data-tags="动态规划">
                <span class="iconfont-archer">&#xe606;</span>
                动态规划
            </span>
        
            <span class="sidebar-tag-name" data-tags="贪心法">
                <span class="iconfont-archer">&#xe606;</span>
                贪心法
            </span>
        
            <span class="sidebar-tag-name" data-tags="分治法">
                <span class="iconfont-archer">&#xe606;</span>
                分治法
            </span>
        
            <span class="sidebar-tag-name" data-tags="归并排序">
                <span class="iconfont-archer">&#xe606;</span>
                归并排序
            </span>
        
            <span class="sidebar-tag-name" data-tags="SpringBoot">
                <span class="iconfont-archer">&#xe606;</span>
                SpringBoot
            </span>
        
            <span class="sidebar-tag-name" data-tags="VS 2019">
                <span class="iconfont-archer">&#xe606;</span>
                VS 2019
            </span>
        
            <span class="sidebar-tag-name" data-tags="C/C++">
                <span class="iconfont-archer">&#xe606;</span>
                C/C++
            </span>
        
            <span class="sidebar-tag-name" data-tags="AES算法">
                <span class="iconfont-archer">&#xe606;</span>
                AES算法
            </span>
        
    </div>
    <div class="iconfont-archer sidebar-tags-empty">&#xe678;</div>
    <div class="tag-load-fail" style="display: none; color: #ccc; font-size: 0.6rem;">
        缺失模块，请参考主题文档进行安装配置：https://github.com/fi3ework/hexo-theme-archer#%E5%AE%89%E8%A3%85%E4%B8%BB%E9%A2%98
    </div> 
    <div class="sidebar-tags-list"></div>
</div>

        <div class="sidebar-panel-categories">
    <div class="sidebar-categories-name">
    
    </div>
    <div class="iconfont-archer sidebar-categories-empty">&#xe678;</div>
    <div class="sidebar-categories-list"></div>
</div>

    </div>
</div>

        <!-- site-meta -->
        <script>
    var siteMetaRoot = "/"
    if (siteMetaRoot === "undefined") {
        siteMetaRoot = '/'
    }
    var siteMeta = {
        url: "https://mnjic.gitee.io",
        root: siteMetaRoot,
        author: "Coder XiaoLiu"
    }
</script>

        <!-- import experimental options here -->
        <!-- Custom Font -->


        <!-- main func -->
        <script src="/scripts/main.js?v=20211217"></script>
        <!-- dark mode -->
        <script src="/scripts/dark.js?v=20211217"></script>
        <!-- fancybox -->
        <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" defer></script>
        <!-- algolia -->
        
        <!-- busuanzi -->
        
            <script src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>
        
        <!-- CNZZ -->
        
        <!-- async load share.js -->
        
            <script src="/scripts/share.js?v=20211217" async></script>
        
        <!-- mermaid -->
        
    </body>
</html>
